"""
Copyright (c) 2022 Huawei Technologies Co.,Ltd.

openGauss is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:

          http://license.coscl.org.cn/MulanPSL2

THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
"""
"""
Case Type   : 服务端工具
Case Name   : 修改配置文件中参数，同时发送信号量到postgresql.conf时不指定-I或者-D
Create At   : 2021/01/05 
Owner       : opentestcase007
Description :
    1.查看krb_caseins_users默认值
    2.修改配置文件中参数，同时发送信号量到postgresql.conf时不指定-I/-D
    3.清理环境
Expect      :
    1.显示成功
    2.执行成功
    3.成功
History     :
    modified by opentestcase023 at 2023-5-15:最新数据库环境变量中增加PGDATA路径，无需指定-D也可执行成功
"""

import unittest
from yat.test import Node
from yat.test import macro
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger

LOG = Logger()


class Tools(unittest.TestCase):
    def setUp(self):
        LOG.info('----Opengauss_Function_Tools_gs_guc_Case0035开始执行----')
        self.dbuser_node = Node('dbuser')
        self.constant = Constant()
        self.commonsh = CommonSH()

    def test_server_tools(self):
        LOG.info('-----步骤1.查看krb_caseins_users默认值-----')
        sql_cmd = self.commonsh.execut_db_sql(f'show krb_caseins_users;')
        LOG.info(sql_cmd)
        self.assertIn('off', sql_cmd)

        LOG.info('-----步骤2.修改配置文件中参数，不指定-N----')
        check_cmd = f'source {macro.DB_ENV_PATH};' \
            f'gs_guc reload -N all -c krb_caseins_users=off;'
        LOG.info(check_cmd)
        msg = self.dbuser_node.sh(check_cmd).result()
        LOG.info(msg)
        self.assertIn(self.constant.GSGUC_SUCCESS_MSG, msg, 'guc参数设置失败')

    def tearDown(self):
        LOG.info('----------------清理环境-----------------------')
        check_cmd = f'source {macro.DB_ENV_PATH};' \
                    f'gs_guc reload -N all -c krb_caseins_users;'
        LOG.info(check_cmd)
        msg = self.dbuser_node.sh(check_cmd).result()
        LOG.info(msg)
        self.assertIn(self.constant.GSGUC_SUCCESS_MSG, msg, 'guc参数设置失败')
        LOG.info('----Opengauss_Function_Tools_gs_guc_Case0035执行结束----')
